package com.sunlands.zlcx.usercenter.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sunlands.zlcx.usercenter.vo.LearnContentVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.beans.BeanUtils;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author shixiaopeng
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "tz_learn_content")
@DynamicUpdate
@DynamicInsert
public class LearnContentDO implements Serializable {

    private static final long serialVersionUID = -5142975848079627189L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 用户表tz_user的id
     */
    private Long userId;

    /**
     * 学习内容
     */
    private String content;

    /**
     * 计时分钟数
     */
    private Integer minutes;

    /**
     * 图标
     */
    private String imageUrl;
    /**
     * @see ModelEnum
     * 计时模式：1正计时，2倒计时
     */
    private Integer model;
    /**
     * @see DeleteEnum
     * 是否删除，1已删，0未删除
     */
    private Integer isDelete;
    /**
     * 学习状态，1未计时，2计时中，12暂停中，13继续中
     *
     * {@link com.sunlands.zlcx.usercenter.constant.LearningStatus}
     */
    private Integer status;

    /**
     * 背景图
     */
    private String backgroundUrl;

    /**
     * 是否沉浸
     */
    private Boolean steep;

    /**
     * 文案
     */
    private String copy;

    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(insertable = false, updatable = false)
    Date updateTime;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(insertable = false, updatable = false)
    Date createTime;

    public enum ModelEnum {
        invalid(1, "正计时"),
        valid(2, "倒计时");

        public final Integer code;
        public final String desc;

        ModelEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }

    public enum DeleteEnum {
        YES(1, "已删"),
        NO(0, "未删");

        public final Integer code;
        public final String desc;

        DeleteEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }


    public static LearnContentDO fromDO(LearnContentVO learnContentVO) {
        if (Objects.isNull(learnContentVO)) {
            return null;
        }
        LearnContentDO learnContentDTO = new LearnContentDO();
        BeanUtils.copyProperties(learnContentVO, learnContentDTO);

        return learnContentDTO;
    }

}
